package com.bohua.intermediary.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bohua.intermediary.common.Lay;
import com.bohua.intermediary.common.Msg;
import com.bohua.intermediary.entity.SysRole;
import com.bohua.intermediary.entity.SysUser;
import com.bohua.intermediary.security.MyUser;
import com.bohua.intermediary.service.SysUserService;
import com.bohua.intermediary.utils.SecurityUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.security.Principal;

/**
 * 控制器
 * @author qian
 * @email 1415261159@qq.com
 * @date 2019/01/19
 */
@Controller
@RequestMapping("/sysUser")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;

    @RequestMapping
    public String sysUser(){
        return "sysUser/sysUser";
    }
    @RequestMapping("/add")
    public String add(){
        return "sysUser/addSysUser";
    }

    @RequestMapping("/update")
    public String update(){
        return "sysUser/updateSysUser";
    }

    @RequestMapping("/getSysUsers")
    @ResponseBody
    public Lay getSysUsers(SysUser sysUser,Integer page,Integer limit){
        return sysUserService.getSysUsers(sysUser,page,limit);
    }
    @RequestMapping("/addSysUser")
    @ResponseBody
    public Msg addSysUser(SysUser sysUser){

        MyUser user= SecurityUtils.getUser();
        sysUser.setOperName(user.getMeUser().getName());
        //System.out.println("当前登录人的信息："+JSON.toJSONString(user));
        //sysUser.setOperName(user.);
        return sysUserService.addSysUser(sysUser);
    }

    @RequestMapping("/updateSysUser")
    @ResponseBody
    public Msg updateSysUser(SysUser sysUser){
        return sysUserService.updateSysUser(sysUser);
    }

    @RequestMapping("/delSysUser")
    @ResponseBody
    public Msg delSysUser(SysUser sysUser){
        return sysUserService.delSysUser(sysUser);
    }
}
